import type {
  balanceLogParams,
  balanceLogResult,
  dashboardResult,
  profileDetail,
  profileParams,
} from '@/types/member'
import { request } from '@/utils/request'

export const getMemberProfileApi = () => {
  return request<profileDetail>({
    method: 'GET',
    url: '/user/info',
  })
}

export const putMemberProfileApi = (data: profileParams) => {
  return request<profileDetail>({
    method: 'POST',
    url: '/user/edit',
    data,
  })
}

export const getBalanceLogApi = (data: balanceLogParams) => {
  return request<balanceLogResult>({
    method: 'GET',
    url: '/user/balanceLog',
    data,
  })
}

// 获取用户面板数据
export const getDashboardApi = () => {
  return request<dashboardResult>({
    method: 'GET',
    url: '/user/dashboard',
  })
}

// 获取我的积分
export const userPoints = () => {
  return request({
    url: '/user/userPoints',
    method: 'GET',
  });
}

//获取用户积分明细列表
/**
 * 
 * @param params type 1:增加 0:减少 
 * @returns 
 */
export const userPointsLogList = (params: { page: number, pageSize: number, type?: string }) => {
  let url = `/user/UserPointsLogList?page=${params.page}&pageSize=${params.pageSize}`
  if (params.type !== null) url += `&type=${params.type}`
  return request({
    url,
    method: 'GET',
  });
}

/**
 * 修改密码
 * @param data
 * @returns
 */
export const changePasswordApi = (data: { old_password: string; new_password: string }) => {
  return request<boolean>({
    method: 'POST',
    url: '/user/changePassword',
    data,
  })
}

/**
 * 重置密码
 * @param data
 * @returns
 */
export const resetPasswordApi = (data: {
  phone: string
  sms_captcha_code: string
  new_password: string
}) => {
  return request({
    method: 'POST',
    url: '/user/resetPassword',
    data,
  })
}

export const verificationApi = (data: { password: string; sms_captcha_code: string }) => {
  return request<{
    verificationToken: string
  }>({
    method: 'POST',
    url: '/user/verification',
    data,
  })
}

export const changeBindApi = (data: {
  phone: string
  sms_captcha_code: string
  verification_token: string
}) => {
  return request({
    method: 'POST',
    url: '/user/changeBind',
    data,
  })
}
